﻿using System;
using System.Collections.Generic;
using System.Linq;
using FBEntities.FBConnections.User;
using Newtonsoft.Json.Linq;
using XDAFacebook;
using XFControls.Utils;

namespace FBEntities.FBObjects
{
    public class FBAlbum : IFBObject
    {
        public FBComments comments;
        public int count;
        public DateTime created_time;
        public string description;
        public FBFrom from;
        public string id;
        public string link;
        public string location;
        public string name;
        protected FBPhotos photos;
        public string picture;
        public string type;
        public DateTime updated_time;

        public FBPhotos Photos
        {
            get
            {
                if (photos == null)
                    photos = new FBPhotos();

                return photos;
            }
            protected set { photos = value; }
        }

        #region IFBObject Members

        public void Parse(JObject text)
        {
            FBParseUtilities.Parse(text, this);
            picture = "https://graph." + Settings.Domain + ".com/" + id + "/picture?" + FBParseUtilities.authKey;
        }

        #endregion

        public WebDownloaderWrapper Create()
        {
            string authKeyCode = FBParseUtilities.authKeySplit;
            var args = new Dictionary<string, string>();
            args.Add("access_token", authKeyCode);
            args.Add("name", name);
            if (!string.IsNullOrEmpty(description))
                args.Add("description", description);

            var ret = new WebDownloaderWrapper("https://graph." + Settings.Domain + ".com/me/albums") { PostData = args };

            return ret;
        }
    }
}